package com.lvchen.common.base;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lvchen.R;
import com.lvchen.common.MyApplication;

import org.json.JSONException;

import java.io.UnsupportedEncodingException;

import okhttp3.Response;


/**
 * @author joe.xiao
 * @Date 2016年3月29日
 * @Email xiaobenqiao027@163.com
 * @Description
 */
public abstract class BaseActivity extends FragmentActivity {

    public Context context;

    public <K extends View> K getViewById(int id) {
        return (K) getWindow().findViewById(id);
    }

    protected Context mContext;
    protected BaseActivity mActivity;
    protected LinearLayout parent;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context=this;

        AppManager.getAppManager().addActivity(this);
        mContext = MyApplication.getInstance();
        mActivity = this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * @Description 刷新一下
     */
    protected void doRetryAction() {

    }

    @Override
    protected void onResume() {
        super.onResume();

        try {
            MyApplication.getInstance().appResume();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
        MyApplication.getInstance().appStop();
    }

    @Override
    public void onBackPressed() {
        // 物理返回键处理。一般UI返回键也是调用此方法
        if (parent != null && null != parent.getChildAt(0) && parent.getChildAt(0).getVisibility() == View.VISIBLE) {

        } else {
            AppManager.getAppManager().finishActivity(this);
        }

    }


    public OnClickListener finishActivityClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            AppManager.getAppManager().finishActivity(mActivity);
        }
    };

}
